package com.my.controller;

import com.my.request.WecomGroupAddReq;
import com.my.request.WecomGroupChangeReq;
import com.my.request.WecomGroupQueryReq;
import com.my.request.WecomGroupUpdateReq;
import com.my.response.WecomGroupDetailResponse;
import com.my.response.WecomGroupResponse;
import com.my.result.PageResult;
import com.my.result.Result;
import com.my.service.WecomRobotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author sjx
 * @date 2025/2/12 10:36
 */
@Slf4j
@RestController
@RequestMapping("/wecomGroup")
public class WecomGroupController {

    @Autowired
    private WecomRobotService wecomRobotService;

    @PostMapping("/list")
    public Result<PageResult<WecomGroupResponse>> list(@RequestBody @Valid WecomGroupQueryReq query) {
        PageResult<WecomGroupResponse> page = wecomRobotService.getPage(query);
        return Result.ok(page);
    }

    @GetMapping("/detail/{wecomGroupId}")
    public Result<WecomGroupDetailResponse> getById(@PathVariable Long wecomGroupId) {
        WecomGroupDetailResponse info = wecomRobotService.getInfo(wecomGroupId);
        return Result.ok(info);
    }

    @PostMapping("/add")
    public Result<Void> add(@RequestBody @Valid WecomGroupAddReq request) {
        wecomRobotService.addInfo(request);
        return Result.ok();
    }

    @PostMapping("/upById")
    public Result<Void> upById(@RequestBody @Valid WecomGroupUpdateReq request) {
        wecomRobotService.updateInfo(request);
        return Result.ok();
    }

    @DeleteMapping("/del/{wecomGroupId}")
    public Result<Void> delById(@PathVariable Long wecomGroupId) {
        wecomRobotService.delById(wecomGroupId);
        return Result.ok();
    }

    @PostMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody @Valid WecomGroupChangeReq request) {
        wecomRobotService.changeStatus(request);
        return Result.ok();
    }

}
